var limsQualitycontrolplan = Gikam.getPageObject({
    // selectItems: [{value: '1', text: '1'}, {value: '2', text: '2'}],
    selectItems: [],
    getEditListColumns: function () {
        return [{
            checkbox: true
        }, {
            index: true
        }, {
            field: 'planCode',
            title: 'T_LIMS_QUALITYCONTROLPLAN.PLANCODE',
            width: 230
        }, {
            field: 'identifyCode',
            title: 'T_LIMS_QUALITYCONTROLPLAN.IDENTIFYCODE'
        }, {
            field: 'mainBatchCode',
            title: 'T_LIMS_QUALITYCONTROLPLAN.MAINBATCHCODE'
        }, {
            field: 'controlMaterialName',
            title: 'T_LIMS_QUALITYCONTROLPLAN.CONTROLMATERIALNAME'
        }, {
            field: 'controlMaterialLevel',
            title: 'T_LIMS_QUALITYCONTROLPLAN.CONTROLMATERIALLEVEL',
            type: 'select',
            category: 'sys',
            param: {
                codeCategoryId: 'controlMaterialLevel'
            }
        }, {
            field: 'expirationDate',
            title: 'T_LIMS_QUALITYCONTROLPLAN.EXPIRATIONDATE',
            width: 170
        }, {
            field: 'manufacturer',
            title: 'T_LIMS_QUALITYCONTROLPLAN.MANUFACTURER'
        }, {
            field: 'equipmentName',
            title: 'T_LIMS_QUALITYCONTROLPLAN.EQUIPMENTNAME'
        }, {
            field: 'ext$.professionalgrouptext',
            title: 'T_LIMS_QUALITYCONTROLPLAN.PROFESSIONALGROUP',
            // type: 'select',
            // category: 'sys',
            // param: {
            //     codeCategoryId: 'qualityControl-professionalGroup'
            // }
        }, {
            field: 'activeStatus',
            title: 'T_LIMS_QUALITYCONTROLPLAN.ACTIVESTATUS',
            type: 'select',
            category: 'sys',
            param: {
                codeCategoryId: 'controlMaterialActiveStatus'
            }
        }, {
            field: 'activeFromDate',
            title: 'T_LIMS_QUALITYCONTROLPLAN.ACTIVEFROMDATE',
            width: 170
        }, {
            field: 'activeToDate',
            title: 'T_LIMS_QUALITYCONTROLPLAN.ACTIVETODATE',
            width: 170
        }];
    },

    getBaseInfoFormFields: function () {
        return [{
            field: 'controlMaterialName',
            title: 'T_LIMS_QUALITYCONTROLPLAN.CONTROLMATERIALNAME',
            validators: ['notEmpty', 'strLength[0,33]'],
            type: 'choose',
            category: 'controlmaterial-choose',
            single: true,
            editor: true,
            cleanable: false,
            onAfterChoose: function (rows, index) {
                if (!Gikam.isEmpty(rows)) {
                    limsQualitycontrolplan.level = Gikam.postText(IFM_CONTEXT + '/secure/core/module/sys/codes/queries', Gikam.getJsonWrapper({
                        f: {
                            code_IN: rows[0].controlMaterialLevel,
                            codeCategoryId_EQ: 'controlMaterialLevel'
                        }
                    })).done(function (data) {
                        data = JSON.parse(data)
                        if (!Gikam.isEmpty(data.rows)) {
                            var selectItems_ = data.rows.map(function (item) {
                                return {
                                    text: item.codeName,
                                    value: item.code
                                }
                            })
                            limsQualitycontrolplan.selectItems = selectItems_
                            Gikam.getComp('lims-qualitycontrolplan-base-info-form').setSelectOptions('controlMaterialLevel', selectItems_);
                        }
                    })
                    this.setData({
                        controlMaterialId: rows[0].id,
                        mainBatchCode: rows[0].mainBatchCode,
                        controlMaterialName: rows[0].controlMaterialName,
                        controlMaterialLevel: '',
                        expirationDate: rows[0].expirationDate,
                        manufacturer: rows[0].manufacturer
                    });
                }
            },
            onBeforeChoose: function () {
                return {
                    filter_method: '1'
                }
            },
            preInsert: true
        }, {
            field: 'controlMaterialLevel',
            title: 'T_LIMS_QUALITYCONTROLPLAN.CONTROLMATERIALLEVEL',
            type: 'select',
            validators: ['notEmpty'],
            items: limsQualitycontrolplan.selectItems,
            preInsert: true,
            firstBlank: false
        }, {
            field: 'identifyCode',
            title: 'T_LIMS_QUALITYCONTROLPLAN.IDENTIFYCODE',
            preInsert: true,
            validators: ['notEmpty', 'strLength[1,48]', 'remote[/secure/basemodule/business/qualitycontrol/qualitycontrolplans/action/validate-unique]'],
        }, {
            field: 'equipmentName',
            title: 'T_LIMS_QUALITYCONTROLPLAN.EQUIPMENTNAME',
            validators: ['strLength[0,33]', 'notEmpty'],
            type: 'choose',
            category: 'equipment',
            single: true,
            editor: true,
            preInsert: true,
            cleanable: false,
            onAfterChoose: function (rows, index) {
                if (!Gikam.isEmpty(rows)) {
                    this.setData({
                        equipmentName: rows[0].equipName,
                        equipmentId: rows[0].id
                    })
                }
            }
        }, {
            field: 'professionalGroup',
            title: 'T_LIMS_QUALITYCONTROLPLAN.PROFESSIONALGROUP',
            validators: ['strLength[0,33]', 'notEmpty'],
            type: 'select',
            // category: 'sys',
            // param: {
            //     codeCategoryId: 'qualityControl-professionalGroup'
            // },
            preInsert: true,
            // firstBlank: false
            // 2022-05-13 专业组改为从基础静态数据-专业组管理获取，表为T_LIMS_GROUP，value为id，text为groupName
        }, {
            field: 'activeFromDate',
            validators: ['notEmpty'],
            title: 'T_LIMS_QUALITYCONTROLPLAN.ACTIVEFROMDATE',
            type: 'dateTime',
            preInsert: true
        }, {
            field: 'activeToDate',
            validators: ['notEmpty'],
            title: 'T_LIMS_QUALITYCONTROLPLAN.ACTIVETODATE',
            type: 'dateTime',
            preInsert: true
        }];
    },

    getProjectEditListColumns: function () {
        return [{
            checkbox: true
        }, {
            index: true
        }, {
            field: 'productCode',
            title: 'T_LIMS_QUALITYCONTROLPLAN_PROJECT.PRODUCTCODE'
        }, {
            field: 'productName',
            title: 'T_LIMS_QUALITYCONTROLPLAN_PROJECT.PRODUCTNAME',
            width: 230
        }, {
            field: 'methodDesc',
            title: 'T_LIMS_QUALITYCONTROLPLAN_PROJECT.METHODDESC',
            readonly: true,
            width: 230
        }, {
            field: 'targetValue',
            title: 'T_LIMS_QUALITYCONTROLPLAN_PROJECT.TARGETVALUE'
        }, {
            field: 'standardDeviation',
            title: 'T_LIMS_QUALITYCONTROLPLAN_PROJECT.STANDARDDEVIATION'
        }, {
            field: 'cvValue',
            title: 'T_LIMS_QUALITYCONTROLPLAN_PROJECT.CVVALUE'
        }, /*{
            field: 'controlRule',
            title: 'T_LIMS_QUALITYCONTROLPLAN_PROJECT.CONTROLRULE',
            type: 'select',
            category: 'sys',
            multiple: true,
            param: {
                codeCategoryId: 'qualityControlRule'
            },
            width: 170
        },*/
            //质控规则改为从质控规则页面的数据里获取，挑选项改为查库，列表显示也修改成查库的
            {
                field: 'ext$.controlrulename',
                title: 'T_LIMS_QUALITYCONTROLPLAN_PROJECT.CONTROLRULE',
                sort: false,
            }];
    },

    getProjectBaseInfoFormFields: function () {
        return [{
            field: 'productName',
            title: 'T_LIMS_QUALITYCONTROLPLAN_PROJECT.PRODUCTNAME',
            validators: ['strLength[0,33]', 'notEmpty'],
            type: 'choose',
            // category: 'groupandmethod-choose',
            category: 'productandmethod-choose',
            single: true,
            editor: true,
            preInsert: true,
            cleanable: false,
            onAfterChoose: function (req) {
                if (!Gikam.isEmpty(req)) {
                    console.log(req)
                    this.setData({
                        productCode: req.productRow.productCode,
                        productName: req.productRow.productName,
                        productId: req.productRow.id,
                        methodId: req.methodRow.id,
                        methodDesc: req.methodRow.purposeName,
                    })
                }
            },
            onBeforeChoose: function () {
                return {
                    type_EQ: 'PJ'
                }
            },
        }, {
            field: 'methodDesc',
            title: 'T_LIMS_QUALITYCONTROLPLAN_PROJECT.METHODDESC',
            editable: false,
            validators: ['notEmpty'],
            preInsert: true
        }, {
            field: 'targetValue',
            title: 'T_LIMS_QUALITYCONTROLPLAN_PROJECT.TARGETVALUE',
            validators: ['number', 'notEmpty'],
            type: 'number',
            preInsert: true,
            onChange: function (field, value, index) {
                if (value !== null)
                    limsQualitycontrolplan.setCalculateData(field)
            }
        }, {
            field: 'standardDeviation',
            title: 'T_LIMS_QUALITYCONTROLPLAN_PROJECT.STANDARDDEVIATION',
            validators: ['number', 'notEmpty'],
            type: 'number',
            preInsert: true,
            onChange: function (field, value, index) {
                if (value !== null)
                    limsQualitycontrolplan.setCalculateData(field)
            }
        }, {
            field: 'cvValue',
            title: 'T_LIMS_QUALITYCONTROLPLAN_PROJECT.CVVALUE',
            validators: ['number', 'notEmpty'],
            type: 'number',
            preInsert: true,
            onChange: function (field, value, index) {
                if (value !== null)
                    limsQualitycontrolplan.setCalculateData(field)
            }
        }, {
            field: 'controlRule',
            title: 'T_LIMS_QUALITYCONTROLPLAN_PROJECT.CONTROLRULE',
            type: 'select',
            validators: ['notEmpty'],
            multiple: true,
            preInsert: true,
            firstBlank: false
        }];
    },

    setCalculateData: function (field) {
        var form = Gikam.getComp('lims-qualitycontrolplanproject-base-info-form')
        var formData = form.getData()
        var targetValue = formData.targetValue
        var standardDeviation = formData.standardDeviation
        var cvValue = formData.cvValue
        switch (field) {
            case 'targetValue':
                if (standardDeviation != null && parseFloat(targetValue) != 0) {
                    form.setData({
                        cvValue: ((parseFloat(standardDeviation) / parseFloat(targetValue)) * 100).toFixed(3)
                    })
                } else if (cvValue != null) {
                    form.setData({
                        standardDeviation: (parseFloat(cvValue) * parseFloat(targetValue)).toFixed(3)
                    })
                }
                break
            case 'standardDeviation':
                if (targetValue != null && parseFloat(targetValue) != 0) {
                    form.setData({
                        cvValue: ((parseFloat(standardDeviation) / parseFloat(targetValue)) * 100).toFixed(3)
                    })
                } else if (cvValue != null && parseFloat(cvValue) != 0) {
                    form.setData({
                        targetValue: (parseFloat(standardDeviation) / parseFloat(cvValue)).toFixed(3)
                    })
                }
                break
            case 'cvValue':
                if (targetValue != null) {
                    form.setData({
                        standardDeviation: (parseFloat(cvValue) * parseFloat(targetValue)).toFixed(3)
                    })
                } else if (standardDeviation != null && parseFloat(cvValue) != 0) {
                    form.setData({
                        targetValue: (parseFloat(standardDeviation) / parseFloat(cvValue)).toFixed(3)
                    })
                }
                break
        }
    },

    getChooseListColumns: function () {
        return [{
            field: 'identifyCode',
            title: 'T_LIMS_QUALITYCONTROLPLAN.IDENTIFYCODE'
        }, {
            field: 'planCode',
            title: 'T_LIMS_QUALITYCONTROLPLAN.PLANCODE'
        }, {
            field: 'mainBatchCode',
            title: 'T_LIMS_QUALITYCONTROLPLAN.MAINBATCHCODE'
        }, {
            field: 'controlMaterialName',
            title: 'T_LIMS_QUALITYCONTROLPLAN.CONTROLMATERIALNAME'
        }, {
            field: 'controlMaterialLevel',
            title: 'T_LIMS_QUALITYCONTROLPLAN.CONTROLMATERIALLEVEL',
            type: 'select',
            category: 'sys',
            multiple: true,
            param: {
                codeCategoryId: 'controlMaterialLevel'
            }
        }, {
            field: 'expirationDate',
            title: 'T_LIMS_QUALITYCONTROLPLAN.EXPIRATIONDATE'
        }, {
            field: 'manufacturer',
            title: 'T_LIMS_QUALITYCONTROLPLAN.MANUFACTURER'
        }, {
            field: 'equipmentName',
            title: 'T_LIMS_QUALITYCONTROLPLAN.EQUIPMENTNAME'
        }, {
            field: 'ext$.professionalgrouptext',
            title: 'T_LIMS_QUALITYCONTROLPLAN.PROFESSIONALGROUP',
            // type: 'select',
            // category: 'sys',
            // param: {
            //     codeCategoryId: 'qualityControl-professionalGroup'
            // },
        }, {
            field: 'activeStatus',
            title: 'T_LIMS_QUALITYCONTROLPLAN.ACTIVESTATUS'
        }, {
            field: 'activeFromDate',
            title: 'T_LIMS_QUALITYCONTROLPLAN.ACTIVEFROMDATE'
        }, {
            field: 'activeToDate',
            title: 'T_LIMS_QUALITYCONTROLPLAN.ACTIVETODATE'
        },];
    },

    baseProjectUrl: IFM_CONTEXT + '/secure/basemodule/business/qualitycontrol/qualitycontrolplan-projects',
    baseUrl: IFM_CONTEXT + '/secure/basemodule/business/qualitycontrol/qualitycontrolplans',
    choseControlmaterialUrl: IFM_CONTEXT + '/secure/basemodule/business/qualitycontrol/controlmaterials' + '/page/choose-list',

    baseGroupUrl: IFM_CONTEXT + '/secure/basemodule/basedata/groups'
});
